package ar.edu.utn.frgp.Banco.actions;

import ar.edu.utn.frgp.Banco.model.Cuenta;
import ar.edu.utn.frgp.Banco.service.IRecursoService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;

public class CuentaAction extends ActionSupport implements ModelDriven<Cuenta> {
	
	private static final long serialVersionUID = 1L;
	
	private String msj;
	
	private Cuenta cuenta = new Cuenta();
	@Autowired
	private IRecursoService recursoService;

	@Override
	public String execute() {
					
		if(String.valueOf((cuenta.getId())) == null || String.valueOf(cuenta.getId()).isEmpty()) {
			setMsj("Numero Invalido");
			return ERROR;
		}
		try {
			recursoService.crearCuenta(cuenta);
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}

	
	public Cuenta getModel() {
		return cuenta;
	}

	public String getMsj() {
		return msj;
	}

	public void setMsj(String msj) {
		this.msj = msj;
	}
}
